#!/bin/bash
# Create a new repository on the command line
model_name=$1
#由python程序判断文件夹是否存在
GIT_DIR=/data1/xyz/modelops-git/${model_name}/${model_name}.git
cd /data1/xyz/modelops-git
mkdir $model_name
cd $model_name
mkdir ${model_name}.git
cd ${model_name}.git
git init --bare
cd hooks
touch post-receive
chmod +x post-receive
echo "#!/bin/sh" >> post-receive
echo "while read oldrev newrev ref" >> post-receive
echo "do" >> post-receive
echo '  branch=`echo $ref | cut -d/ -f3`' >> post-receive
echo "git --work-tree=/data1/xyz/modelops-git/$model_name --git-dir=$GIT_DIR checkout -f \$branch" >> post-receive
echo "done" >> post-receive
cd /data1/xyz/modelops-git
chown -R xyz $model_name
exit 0

#git --work-tree=/home/modelops-git/test --git-dir=/home/modelops-git/test/test.git